<template>
    <div class="article_serach">
        <div class="home-header">
            <div class="home-index-search">
                <i class="iconfont icon-sousuo"></i>
                <input type="text" placeholder="搜索" v-model="monasteryname">
                <i class="iconfont icon-guanbi" @click="clearFn()"></i>
            </div>

            <span class="article_search_cancel" @click="onClickLeft">取消</span>
        </div>


         <!-- 历史记录 -->
        <div class="history_record" v-if="state">
            <!-- <i class="iconfont icon-guanbi"></i> -->
            <h2>历史搜索</h2>
            <div class="history_cont">
                <div class="history_item" v-for="(item, indexs) of list" :key="indexs" v-if="indexs < index" @click="router(item)">{{ item.title.length > 16 ? `${item.title.substr(0,16)}...`: item.title}}</div>
            </div>
        </div>
        <!-- 历史记录end -->

        <div class="pray-item-list" v-else>
            <div class="pray-item-li" @click="router(item)" v-for="(item, index) of list" :key="index" v-if="list.length > 0">
                <div class="pray-item-img">
                    <div class="hot" v-if="item.ishot == 1">热门</div>
                    <div class="stick" v-if="item.issettop == 1">置顶</div>
                    <img :src="item.showpicture" alt="">
                </div>
                
                <div class="pray-item-cont">
                    <h2>{{ item.title.length > 16 ? `${item.title.substr(0,16)}...`: item.title}}</h2>
                    <div class="pray-item-time">{{ item.publishtime }}</div>
                    <div class="pray-item-view">
                        <span><i class="iconfont icon-chakanliang-"></i>{{ item.visitnum}}</span>
                        <span><i class="iconfont icon-renwu-"></i>{{ item.author }}</span>
                    </div>
                </div>
            </div>

            <div class="empty"  v-if="list.length <= 0">
                <i class="iconfont icon-kongzhuangtai-"></i>
                <span>没有找到您想要的内容</span>
            </div>
        </div>

    </div>
</template>
<script>
import {getResponse, getResponses} from "../api"
export default {
    data() {
        return {
            querytype:'',
            articlesetid:'',
            monasteryname:'',
            pagenum:1,
            pagesize:10,
            total:0,
            list:[],
            state:true,
            index:0
        }
    },

    watch:{
        monasteryname() {
            this.getMusic()
        }
    },

    methods:{
        onClickLeft() {
            this.$router.go(-1)
        },

        clearFn() {
            this.monasteryname = ''
        },

        router(item) {

            if(item.articlejumpurl != '' && !!item.articlejumpurl) {
                location.href = item.articlejumpurl 
                return false;
            }

            if( item.isarticleset == 1) {
                this.$router.push(`/article_set?articlesetid=${item.articlesetid}`)
                return false
            }

            this.$router.push(`/pray_details?id=${item.articleid}&showtype=${item.showtype}`)
        },

        routers(url) {
            this.$router.push(url)
        },

        switchFn(name) {
            this.monasteryname = name
        },
        //寺庙列表
        async getMusic(type) {

            const data = await getResponses(`/fochina/query/articlelist/json`,{'querytype':this.querytype, 'articlesetid': this.articlesetid	, 'title': this.monasteryname, 'pagenum':this.pagenum,'pagesize':10})
            if(data.code === '0000') {
                this.state = this.monasteryname == ''
                this.list = data.data
            } else {
                console.log(data.error)
            }
        },
    },

    mounted() {
        this.index = parseInt(Math.random() * 10)
        this.articlesetid = this.$route.query.articlesetid || ''
        this.querytype = this.articlesetid != '' ? 2 : 0
        this.getMusic()
    }
}
</script>
<style scoped>
.pray-item-li {
    width:100%;
    height: 2.1rem;
    border-bottom: 1px solid #eee;
    display: flex;
    padding:0.25rem 0;
    box-sizing: border-box;
    background-color: #fff;
    margin-bottom: 0.2rem;
    position: relative;
}

.pray-item-li img {
    width: 1.6rem;
    height: 1.6rem;
}

.pray-item-cont {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

.pray-item-cont h2 {
    font-family: PingFangSC-Regular;
    font-size: 0.32rem;
    color: #333333;
    text-align: left;
}

.pray-item-cont .pray-item-view {
    font-family: PingFangSC-Regular;
    font-size: 0.24rem;
    color: #999999;
   
}

.pray-item-cont .pray-item-view  span{
    display: inline-flex;
    align-items: center;
    min-width: 2rem;
}

.pray-item-cont .pray-item-view  span i {
    margin-right: 0.1rem;
}

.pray-item-cont .pray-item-time {
    font-family: PingFangSC-Regular;
    font-size: 0.24rem;
    color: #999999;
    text-align: left;
}

.pray-item-li .pray-item-img .stick {
    transform: translate(50%, -50%) rotate(45deg);
    font-size:0.14rem;
    color: #FFFFFF;
    background-image: linear-gradient(-45deg, #B63532 50%, #A92926 100%);
    border-radius: 0 0.08rem 0;
    width:1.2rem;
    height: 1rem;
    position:absolute;
    top:0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    border-radius: 0px;
    padding-bottom: 0.1rem;
}

.pray-item-li .pray-item-img {
    position: relative;
    width: 1.6rem;
    height: 1.6rem;
    margin-right: 0.26rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pray-item-li .pray-item-img .hot {
    /* opacity: 0.6; */
    background:#ffffff99;
    border-radius: 4px;
    width:0.6rem;
    height: 0.3rem;
    font-size: 0.18rem;
    color: #A92926;
    position: absolute;
    top:0.06rem;
    left:0.1rem;
    display: flex;
    justify-content: center;
    align-items: center;
}


.pray-item-list {
    margin-top:0.2rem;
    width:100%;
    padding:0 0.25rem;
    box-sizing: border-box;
    background-color: #fff;
    border-top:0.01rem solid #eee;
}


/* .article_search_cancel {
    font-family: PingFangSC-Regular;
    font-size: 0.34rem;
    color: #FFF;
}
 */

.article_search_cancel {
    font-family: PingFangSC-Regular;
    font-size: 0.34rem;
    color: #FFF;
    min-width:0.7rem;
    height: 0.6rem;
    margin-left:0.2rem;
    display: flex;
    align-items: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history_cont {
    display: flex;
    flex-wrap: wrap;
}

.history_item {
    min-width: 1.46rem;
    height: 0.46rem;
    background: #E9EAEC;
    border-radius: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: PingFangSC-Regular;
    font-size: 0.28rem;
    color: #333;
    margin-right:0.16rem;
    margin-bottom:0.16rem;
    padding:0 0.2rem;
}

.article_serach .home-header {
    height: 1rem;
    width:100%;
    background-image: linear-gradient(-90deg, #B3A277 0%, #AB946C 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding:0 0.14rem 0 0.24rem;
}

.article_serach .home-index-search {
    width:6.2rem;
    height: 0.6rem;
    background-color:#fff;
    position: relative;
    
    box-sizing: border-box;
}

.home-index-search i.icon-sousuo{
    position: absolute;
    top:50%;
    transform: translateY(-50%);
    left:0.28rem;
    color:#B2B2B2;
}


.home-index-search i.icon-guanbi {
    position: absolute;
    top:50%;
    transform: translateY(-50%);
    right:0.28rem;
    color:#B2B2B2;
}

.article_serach .home-index-search input {
    border:none;
    width:100%;
    height: 0.6rem;
    font-size:0.28rem;
    padding:0 0.68rem 0 0.68rem;
    box-sizing: border-box;
    color:#666
}

.history_record {
    width: 7.5rem;
    background-color: #fff;
    min-height: 100vh;
    padding:0 0.3rem;
    box-sizing: border-box;
    
}

.history_record h2 {
    font-family: PingFangSC-Medium;
    font-size: 0.34rem;
    color: #333;
    justify-content: space-between;
    display: flex;
    text-align: center;
    width:100%;
    padding:0.26rem 0;
}


.item-list {
    width:100%;
    height: 2.3rem;
    border-top:1px solid #E3E3E3;
    border-bottom: 1px solid #E3E3E3;
    display: flex;
    padding:0.25rem;
    box-sizing: border-box;
    background-color: #fff;
    margin-bottom: 0.2rem;
}

.item-list img {
    width:1.8rem;
    height: 1.8rem;
    border-radius: 10px;
    margin-right:0.34rem;
}

.item-list h2 {
    font-size:0.34rem;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.14rem;
}

.item-list h2 span {
    font-size: 0.24rem;
    color: #999;
}

.item-list p {
    font-size: 0.28rem;
    color: #666;
    line-height: 0.4rem;
}

.item-list-cont {
    flex:1
}

.item-list-cont p {
    width:100%;
    font-family: PingFangSC-Regular;
    font-size:0.28rem;
    color: #666666;
    text-align: justify;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-height: 1.5;
    height:1.2rem;
    overflow: hidden
}
</style>
